#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#include"heap.h"
//选出最大的k个数 -->建小堆
//选出最小的k个数 -->建大堆
int main()
{
    srand((unsigned int)time(NULL));
    int a[10] = {0};
    int i = 0;
    for(;i<10;i++)
    {
        a[i] = rand() % 20;
        printf("%d ",a[i]);
    }
    printf("\n");
    HP hp;
    HeapInit(&hp);
    int k = 5;
    //1.先建立k个数的堆   ->以选出最小的k个数为例==>建大堆
    i = 0;
    for(;i<k;i++)
    {
        HeapPush(&hp,a[i]);
    }
    //2.后面的数和堆顶元素比较
    i = k;
    for(;i<sizeof(a)/sizeof(a[0]);i++)
    {
        if(a[i] < HeapTop(&hp))
        {
            HeapPop(&hp);
            HeapPush(&hp,a[i]);
        }
    }
    HeapPrint(&hp);
    return 0;
}

